package com.littleHan.brushQuestions.web.userCenter.controller;

import com.alibaba.fastjson.JSON;
import com.littleHan.brushQuestions.common.Result;
import com.littleHan.brushQuestions.exception.FailedSettingException;
import com.littleHan.brushQuestions.web.start.pojo.Comment;
import com.littleHan.brushQuestions.web.start.pojo.Topic;
import com.littleHan.brushQuestions.web.userCenter.pojo.Pagination;
import com.littleHan.brushQuestions.web.userCenter.service.AuditorUserCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/auditorUserCenter")
public class AuditorUserCenterController {

    @Autowired
    private AuditorUserCenterService auditorUserCenterService;

    /**
     * 获取没有被审核的题目
     *
     * @param pagination 分页对象
     * @return
     */
    @PostMapping("/getNoCheckTopicListJ")
    public String getNoCheckTopicList(@RequestBody Pagination pagination) {
        Map<String, Object> map = auditorUserCenterService.getNoCheckTopic(pagination);
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取没有被审核的题目成功").setData(map));
    }

    /**
     * 审核通过
     *
     * @param topic 携带题目id、该题的用户id
     * @return
     */
    @PostMapping("/topicPassedJ")
    public String topicPassed(@RequestBody Topic topic) throws FailedSettingException {
        auditorUserCenterService.topicPassed(topic);
        return JSON.toJSONString(new Result().setCode(200).setMessage("审核通过设置成功"));
    }

    /**
     * 审核未通过
     *
     * @param topic 携带题目id、该题的用户id
     * @return
     * @throws FailedSettingException
     */
    @PostMapping("/topicUnPassedJ")
    public String topicUnPassed(@RequestBody Topic topic) throws FailedSettingException {
        auditorUserCenterService.topicUnPassed(topic);
        return JSON.toJSONString(new Result().setCode(200).setMessage("审核未通过设置成功"));
    }

    /**
     * 获取未审核的评论列表
     */
    @PostMapping("/getNoCheckCommentListJ")
    public String getNoCheckCommentList(@RequestBody Pagination pagination) {
        Map<String, Object> map = auditorUserCenterService.getNoCheckComment(pagination);
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取没有被审核的评论成功").setData(map));
    }

    /**
     * 审核评论通过
     * @param comment 评论信息
     * @return
     */
    @PostMapping("/commentPassedJ")
    public String commentPassed(@RequestBody Comment comment) throws FailedSettingException{
        auditorUserCenterService.commentPassed(comment);
        return JSON.toJSONString(new Result().setCode(200).setMessage("该评论审核通过"));
    }

    /**
     * 该评论审核未通过
     *
     * @param comment 当前评论的id、当前这条评论的用户id
     * @return
     * @throws FailedSettingException
     */
    @PostMapping("/commentUnPassedJ")
    public String commentUnPassed(@RequestBody Comment comment) throws FailedSettingException {
        auditorUserCenterService.commentUnPassed(comment);
        return JSON.toJSONString(new Result().setCode(200).setMessage("该评论审核未通过"));
    }

    /**
     * 获取到当前用户信息
     * @param userId 用户id
     * @return
     */
    @GetMapping("/getThisUserInfo")
    public String getUserInfoByUserId(String userId){
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取当前用户信息成功").setData(auditorUserCenterService.getUserInfoByUserId(userId)));
    }
}
